package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.customer.CustomerInsertDTO;
import com.qk.dto.customer.CustomerListDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import com.qk.vo.customer.CustomerListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author：sch
 * createTime：2025/10/17 19:52
 * description： 
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    //列表查询
    @GetMapping
    public Result customerList(CustomerListDTO dto) {
        PageResult<CustomerListVO> pageResult = customerService.customerList(dto);
        return Result.success(pageResult);
    }
    //添加客户
    @PostMapping
    public Result addCustomer(@RequestBody CustomerInsertDTO dto) {
        customerService.addCustomer(dto);
        return Result.success();
    }
    //根据id查询客户
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Customer customer = customerService.getById(id);
        return Result.success(customer);
    }
    //修改客户
    @PutMapping
    public Result update(@RequestBody Customer customer) {
        customerService.updateById(customer);
        return Result.success();
    }
}